package com.hwl.lab.service;

import com.hwl.lab.entity.Area;
import com.hwl.lab.entity.Handle;
import com.hwl.lab.repository.AreaRepository;
import com.hwl.lab.repository.HandleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HandleService {
    @Autowired
    private HandleRepository handleRepository;
    //分页实现
    public Page<Handle> findAll(Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return handleRepository.findAll(pageable);
    }
    //不分页
    public List<Handle> findAll() {
        return handleRepository.findAll();
    }
    //通过账号查询
    public Handle findByHandleid(String handleid){
        return handleRepository.findByHandleid(handleid);
    }
    //保存，修改
    public Handle saveHandle(Handle handle){
       return  handleRepository.save(handle);
    }
    //通过账号删除
    public void deleteById(Long id){
        handleRepository.deleteById(id);
    }
}
